#include "messagebox.h"
#include <QtWidgets>
#include <QtGui>

GMessageBox::GMessageBox(QWidget *parent)
    : QDialog(parent)
    //, ui(new Ui::MessageBox)
{
    setupUi(this);

    connect(btn1,SIGNAL(clicked()),this,SLOT(slotQuestion()));
       connect(btn2,SIGNAL(clicked()),this,SLOT(slotInformation()));
       connect(btn3,SIGNAL(clicked()),this,SLOT(slotWarning()));
       connect(btn4,SIGNAL(clicked()),this,SLOT(slotCritical()));
       connect(btn5,SIGNAL(clicked()),this,SLOT(slotAbout()));
       connect(btn6,SIGNAL(clicked()),this,SLOT(slotAboutQt()));
       connect(btn7,SIGNAL(clicked()),this,SLOT(slotCustom()));
}

GMessageBox::~GMessageBox()
{
    //delete ui;
}

void GMessageBox::slotQuestion()
{
    switch (QMessageBox::question(this, "Question",
            tr("It's end of document,search from begin?"),
            QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok))
    {
    case QMessageBox::Ok:
            label->setText("Question button/Ok");
            break;
    case QMessageBox::Cancel:
            label->setText("Question button/Cancel");
            break;
    default:
            break;

    }
}

void GMessageBox::slotInformation()
{
    QMessageBox::information(this,"Information",tr("anything you want tell user"));
    return;

}

void GMessageBox::slotWarning()
{
    switch (QMessageBox::warning(this,"Warning",
                                 tr("Save changes to document?"),
                                 QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,
                                 QMessageBox::Save))
    {
    case QMessageBox::Save:
            label->setText("Warning button/Save");
        break;
    case QMessageBox::Discard:
            label->setText("Warning button/Discard");
        break;
    case QMessageBox::Cancel:
            label->setText("Warning button/Cancel");
        break;
    default:
        break;

    }
    return;

}

void GMessageBox::slotCritical()
{
    QMessageBox::critical(this,"Critical",tr("tell user a critical error"));
    label->setText("Critical MessageBox");
    return;

}

void GMessageBox::slotAbout()
{
    QMessageBox::about(this,"About",tr("Message box example!"));
    label->setText("About MessageBox");
    return;

}

void GMessageBox::slotAboutQt()
{
    QMessageBox::aboutQt(this,"About Qt");
    label->setText("About Qt MessageBox");
    return;

}

void GMessageBox::slotCustom()
{
    QMessageBox customMsgBox;
    customMsgBox.setWindowTitle("Custom message box ");

    QPushButton *lockButton = customMsgBox.addButton(tr("Lock"),QMessageBox::ActionRole);
    QPushButton *unlockButton = customMsgBox.addButton(tr("Unlock"),QMessageBox::ActionRole);
    QPushButton *cancelButton = customMsgBox.addButton(QMessageBox::Cancel);

    customMsgBox.setIconPixmap(QPixmap(":/images/linuxredhat.png"));
    customMsgBox.setText(tr("This is a custom message box"));
    customMsgBox.exec();

    if(customMsgBox.clickedButton() == lockButton)
        label->setText("Custom MessageBox/Lock");
    if(customMsgBox.clickedButton() == unlockButton)
        label->setText("Custom MessageBox/Unlock");
    if(customMsgBox.clickedButton() == cancelButton)
        label->setText("Custom MessageBox/Cancel");

    return;

}


